package hc.cn.sp04.order.service;

import hc.cn.sp04.order.feign.ItemClient;
import hc.cn.sp04.order.feign.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sp01.pojo.Item;
import sp01.pojo.Order;
import sp01.pojo.User;
import sp01.service.OrderService;
import web.util.JsonResult;

import java.util.List;

/**
 * @author 海绵宝宝
 * date 2021/10/27 9:32
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    ItemClient itemClient;
    @Autowired
    UserClient userClient;
    @Override
    public Order getOrder(String orderId) {
        log.info("获取订单："+orderId);
        //TODO：远程调用商品，获取商品列表
        JsonResult<List<Item>> list = itemClient.getItem(orderId);
        //TODO:远程调用用户，获取用户数据
        JsonResult<User> user = userClient.getUser(8);
        Order order = new Order();
//        order.setItems(商品列表);
//        order.setUser(用户);
        order.setItems(list.getData());
        order.setUser(user.getData());
        order.setId(orderId);
        return order;
    }

    @Override
    public void addOrder(Order order) {
        log.info("添加订单："+order);
        //TODO:远程调用商品，减少商品库存
        //TODO:远程调用用户，增加用户积分
    }
}
